<html>
<head><meta charset="utf-8"><title>cargo features question · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo.20features.20question.html">cargo features question</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220500762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo%20features%20question/near/220500762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo.20features.20question.html#220500762">(Dec 20 2020 at 03:41)</a>:</h4>
<p>I have a Cargo workspace that has a number of packages. Some packages depend on Serde, and some of those enable the <code>rc</code> feature and some don't. Will Cargo build <code>serde</code> twice, once with <code>rc</code> and once without? If so, is it able to utilize incremental compilation so that it only recompiles the parts that are different?</p>
<p>And, if I enable <code>rc</code> for all of the packages that use <code>serde</code>, will it speed up my build times?</p>
<p>Thanks!</p>



<a name="220500813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo%20features%20question/near/220500813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo.20features.20question.html#220500813">(Dec 20 2020 at 03:43)</a>:</h4>
<p><span class="user-mention" data-user-id="307537">@Camelid</span> cargo unifies features, so if you depend on serde multiple times it will be built with the union of the features from each dependency.</p>



<a name="220500814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo%20features%20question/near/220500814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo.20features.20question.html#220500814">(Dec 20 2020 at 03:43)</a>:</h4>
<p>Or in other words, only built once</p>



<a name="220500861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo%20features%20question/near/220500861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo.20features.20question.html#220500861">(Dec 20 2020 at 03:45)</a>:</h4>
<p>This can get you into trouble if you depend on a feature without actually writing it in cargo.toml<br>
<a href="https://github.com/rust-lang/rustwide/pull/49#issuecomment-725343203">https://github.com/rust-lang/rustwide/pull/49#issuecomment-725343203</a></p>



<a name="220501314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo%20features%20question/near/220501314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo.20features.20question.html#220501314">(Dec 20 2020 at 03:59)</a>:</h4>
<p>Thanks! I thought that might be it.</p>



<a name="220527613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo%20features%20question/near/220527613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo.20features.20question.html#220527613">(Dec 20 2020 at 16:57)</a>:</h4>
<p>That union is also why people say that cargo features should always be additive.</p>



<a name="220534295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/cargo%20features%20question/near/220534295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/cargo.20features.20question.html#220534295">(Dec 20 2020 at 19:48)</a>:</h4>
<p><span class="user-mention silent" data-user-id="307537">Camelid</span> <a href="#narrow/stream/122651-general/topic/cargo.20features.20question/near/220500762">said</a>:</p>
<blockquote>
<p>Will Cargo build <code>serde</code> twice, once with <code>rc</code> and once without?</p>
</blockquote>
<p>In theory, no. In practice, yes if you ever do <code>cargo build -p</code>, <code>cargo build --manifest-dir</code>, etc. Which is hard to avoid, if you want to test enablement of various features or have a big enough workspace that running all tests for every change is slow.</p>
<p>See <a href="https://searchfox.org/mozilla-central/source/build/workspace-hack/Cargo.toml">https://searchfox.org/mozilla-central/source/build/workspace-hack/Cargo.toml</a> for a common "solution" (annoying workaround) to this problem.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>